<template>
    <el-dialog
        v-model="dialogVisible"
        title="操作"
        width="30%"
    >
        <span>请确认是否要回滚至当前配置id {{ configId }}, 配置方案为 {{ configName }}？</span>
        <template #footer>
              <span class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="confirmFn">
                  确定
                </el-button>
              </span>
        </template>
    </el-dialog>
</template>

<script>

import {computed, onMounted, reactive, ref, toRaw, toRefs} from "vue";
import {rollbackHistoryConfigApi} from "@/api/carManage/policyManage.js";
import {ElMessage} from "element-plus";

export default {
    emits: ['feedbackFn'],
    setup(props, {
        attrs,
        slots,
        emit
    }) {
        const dialogVisible = ref(false);

        const id = ref('');
        const configName = ref('');
        const configId = ref('');
        const switchVisible = (row) => {
            dialogVisible.value = true
            id.value = row.id;
            configName.value = row.configInfoId;
            configId.value = row.configId;
            if (row.configInfoType == 0) {
                
                configName.value = 'T' + row.configInfoId;
            } else if (row.configInfoType == 1) {
                configName.value = 'TG' + row.configInfoId;
            }

        }

        const confirmFn = () => {
            dialogVisible.value = false
            let userNo;
            try {
                userNo = JSON.parse(localStorage.getItem('userInfo')).employeeId;
            } catch (e) {
            }
            rollbackHistoryConfigApi({
                id: id.value,
                userNo: userNo
            }).then(res => {

                if (res.data.code === 200) {
                    ElMessage.success("回滚成功！");

                    emit('feedbackFn')

                } else {
                    ElMessage.error("回滚失败！");
                }
            })


        }
        return {
            id,
            dialogVisible,
            switchVisible,
            confirmFn,
            configName,
            configId
        }
    }
}
</script>